if(!jsx3.lang.Class.forName("ux.cdb.admin.loan.loanWizard.BorrowApply")) {
	jsx3.lang.Class.defineClass("ux.cdb.admin.loan.loanWizard.BorrowApply",
			ux.megatron.gui.WizardPanel,
			null,
			function (block) {
				/**
				 * instance initializer
				 * @param strName {String} unique name distinguishing this object from all other JSX GUI objects in the JSX application
				 * @param vntLeft {int|String} either a number (i.e, 12, 30, etc) or a number and a unit value (i.e., "25%", "36pt", etc); if a number is passed, pixels will be the assumed unit when painted to screen
				 * @param vntTop {int|String} either a number (i.e, 12, 30, etc) or a number and a unit value (i.e., "25%", "36pt", etc); if a number is passed, pixels will be the assumed unit when painted to screen
				 * @param vntWidth {int|String} either a number (i.e, 12, 30, etc) or a number and a unit value (i.e., "25%", "36pt", etc); if a number is passed, pixels will be the assumed unit when painted to screen
				 * @param vntHeight {int|String} either a number (i.e, 12, 30, etc) or a number and a unit value (i.e., "25%", "36pt", etc); if a number is passed, pixels will be the assumed unit when painted to screen
				 * @param strHTML {String} Text/HTML markup to place in the jsx3.gui.Block instance
				 */
				block.prototype.init = function(strName, vntLeft, vntTop, vntWidth, vntHeight, strHTML) {
					//call constructor for super class (the super expects the name of the object and the function that it is an instance of)
					this.jsxsuper(strName, vntLeft, vntTop, vntWidth, vntHeight, strHTML);
				};

				block.prototype.onAfterDeserialize = function() {
					jsx3.log('step3 onAfterDeserialize '); 
					if(!this.getChild(0)) {
						var me = this;
						ux.megatron.Main.loadUIResourceAsync(me, "ux.cdb.admin","ux/cdb/admin/loan/loanWizard/step3/ui/BorrowApplyContent.xml", me, me.initialize);
					}
				}

				block.prototype.initialize = function(msg) {
					try{
          	this.wizard = this.getAncestorOfType("ux.cdb.admin.loan.loanWizard.LoanBuilder");
          	this.wizard.appBasicInfoId = "";
          	//this.wizard.get("buttonPrev").setDisplay(jsx3.gui.Block.DISPLAYBLOCK,true);
          	//this.dialog = this.getAncestorOfType("ux.cdb.admin.loan.loanWizard.LoanBuilder");
          
          	this.loadApplyDate();
          	this.get("blkField_studentName").getChild(1).setText(this.wizard.studentName,true);
					this.get("blkField_studtCertId").getChild(1).setText(this.wizard.studentCertId,true);
					this.get("blkField_coDebitName").getChild(1).setText(this.wizard.coDebitName,true);
					this.get("blkField_coDebitCertType").getChild(1).setText(this.wizard.coCertType,true);
					this.get("blkField_coCertId").getChild(1).setText(this.wizard.coCertId,true);
          	var me = this;
          	//ux.cdb.admin.CommonCache.loadCache(['APP_TYPE','APP_REASON'], me, me.onSelectListLoaded);  
          	//this.onSelectListLoaded();
          	jsx3.log('step3 initialize ok!!!!!!!!!!!!!!!!! : '); 
        	} catch(e){
						jsx3.log('step3 initialize: ' + e.message);
					}     
				}

				block.prototype.onSelectListLoaded = function() {
					try{
				//var tip = ux.megatron.Main.getServer().getDynamicProperty("@cdb@LoanManage@MainPage@PleaseSelect");
      			var cache = ux.cdb.admin.CommonCache.getInstance();
      			//jsx3.log('step 3 PleaseSelect: ' + tip);
      			this.get('blkField_appType').getChild(1).setSourceXML(cache.getCache('CommonCache_APP_TYPE'));
      			//this.get("blkField_appType").getChild(1).setValue(tip);
      			  
      			jsx3.log('step 3 CommonCache_APP_REASON : ' + cache.getCache('CommonCache_APP_REASON'));
      			
      			this.get('blkField_appReason').getChild(1).setSourceXML(cache.getCache('CommonCache_APP_REASON'));
      			//this.get('blkField_appReason').getChild(1).setValue(tip);    
      			this.get('blkField_appReason').getChild(1).repaint();
      			this.get('blkField_appType').getChild(1).repaint();
      		}catch(e){
						jsx3.log('step3 onSelectListLoaded callback Error : ' + e.message);
					}
				}

				block.prototype.loadInfo = function() {
        	jsx3.log('step3 loadInfo : this.wizard.applyId' + this.wizard.applyId);
      		var params = [];
      		params.push(null);
      		params.push(null);
      		params.push(this.wizard.applyId);
      		params.push(null);
      		params.push(null);
      		params.push(null);
      		var me = this;
      		ux.megatron.util.Dwr.callDwr("AcceptRetailStudentLoanAppUCC", "getLoanAppUIO", params, me, me.onGetLoanAppUIOCallback, "AcceptRetailStudentLoanAppUCC");
      	}

				block.prototype.onGetLoanAppUIOCallback = function(reData) {
					if(!reData)
						jsx3.log("call getLoanAppUIO failed......");
				
					var flag = reData.res.flag;
        	if(flag != 1){
        		var msg = reData.res.msg;
        		jsx3.log("call getLoanAppUIO failed: "+msg);
        		return;
        	}
			console.log('onGetLoanAppUIOCallback data : \n',reData);
			    	
      		var realData = reData.content.data[0];
      		this.wizard.appBasicInfoId = realData.appBasicInfoId;
      		jsx3.log("onGetLoanAppUIOCallback appAmt:"+ realData.appAmt);  
			this.wizard.loan_step3_data = realData; //cache data
			console.log('onGetLoanAppUIOCallback loan_step2_data cache : \n',this.wizard.loan_step2_data);
			console.log('onGetLoanAppUIOCallback loan_step3_data cache : \n',this.wizard.loan_step3_data);
					this.get("block_loan_step3_gd").setDataByObject(realData);
				}

				block.prototype.loadApplyDate = function() {
        	//ux.megatron.Main.loadResource("ux/cdb/admin/loan/xml/applyDate.xml", "ux.cdb.admin", "loanmanage_0604", "xml");
        	//this.get('blkField_applyDate').getChild(1).repaint();
        	
        	var cdf = jsx3.xml.CDF.Document.newDocument();
                        var currentYear = (new Date()).getFullYear(), id, text;
                        var unit = ux.megatron.Main.getServer().getDynamicProperty("@cdb@LoanManage@LearnYear");
                        for(var i=-1; i<=9; i++) {
                            id = (currentYear+i) + "" + (currentYear+i+1);
                            text = (currentYear+i) + "-" + (currentYear+i+1) + unit;
                            cdf.insertRecord({jsxid: id, jsxtext: text});
                        };
                        this.get("blkField_applyDate").get("selValue").setSourceXML(cdf);
                        this.get('blkField_applyDate').getChild(1).repaint();;
                        this.get("blkField_applyDate").get("selValue").setValue((currentYear) + "" + (currentYear+1));
      	}

				block.prototype.onNext = function(objWIZARD, objBUTTON, objEVENT, strCURRENTPANEL) {
					return null; // return "NONE" to not next panels
				}

				block.prototype.onPrev = function(objWIZARD, objBUTTON, objEVENT, strCURRENTPANEL) {
					return null; // return "NONE" to not advance panels
				}

				block.prototype.onRevert = function(objWIZARD, objBUTTON, objEVENT, strCURRENTPANEL) {
					return null; // return "NONE" to not last status
				}

				block.prototype.onCancel = function(objWIZARD, objBUTTON, objEVENT, strCURRENTPANEL) {
				if(this.wizard.__studentId)
					this.wizard._unlockStudent(this.wizard.__studentId);
					this.getAncestorOfType("ux.cdb.admin.loan.loanWizard.LoanBuilder").onClose();
          //this.wizard.onClose();          
					return null; // return "NONE" to not advance panels
				}

        block.prototype.onFinish = function(objWIZARD, objBUTTON, objEVENT, strCURRENTPANEL) {
        	//this.onSaveData();
          //return null; // return "NONE" to not advance panels
        	var wizard = this.getAncestorOfType("ux.megatron.gui.SteppedWizard");
        	var lbl = wizard.getMessageLabel();//alert("onFinish");
					var result =  this.get("block_loan_step3_gd").doValidate();//alert("onFinish2");
					if(result != null){
						//var tip = ux.megatron.Main.getServer().getDynamicProperty("@cdb@LoanManage@Wizard@WizardSetp2_validateFail");
                        var tip = result[0].label ? result[0].label + ":" + result[0].message : result[0].message;
						lbl.setColor('red');
						lbl.setText(tip,true);
						return 'NONE';
					}
					
					var appAmt = parseInt(this.get("blkField_appAmt").extractData());
					if(isNaN(appAmt) || appAmt<1000 || appAmt>6000){
						var tip = ux.megatron.Main.getServer().getDynamicProperty("@cdb@LoanManage@Wizard@WizardSetp3_appAmtError");
                        //var tip = result[0].label ? result[0].label + ":" + result[0].message : result[0].message;
						lbl.setColor('red');
						lbl.setText(tip,true);
						return 'NONE';
					}
					
					var applyType = this.get("blkField_appType").getChild(1).getValue();
					var requireDate = this.get("blkField_schoolingDate").getChild(1).getValue();
					jsx3.log("saveTwoInfo requireDate: "+ requireDate); 
					var ps = ux.megatron.Main.getServer().getDynamicProperty("@cdb@LoanManage@MainPage@PleaseSelect");
					if(applyType == ps){
						var tip = ux.megatron.Main.getServer().getDynamicProperty("@cdb@LoanManage@Wizard@WizardSetp3_AppType");
						lbl.setColor('red');
						lbl.setText(tip,true);
						return 'NONE';
					}
					if(applyType=="01" && requireDate=="yyyy-MM-dd"){
						var tip = ux.megatron.Main.getServer().getDynamicProperty("@cdb@LoanManage@Wizard@WizardSetp3_schoolingDate");
						lbl.setColor('red');
						lbl.setText(tip,true);
						return 'NONE';
					}
					
					var shenchaqingkuang1 = this.get("blkField_dealer1").getChild(1).getValue();
					var shenchaqingkuang2 = this.get("blkField_dealer2").getChild(1).getValue();
					if((shenchaqingkuang1==null || shenchaqingkuang1=="")&& (shenchaqingkuang2==null || shenchaqingkuang2=="")){
						var tip = ux.megatron.Main.getServer().getDynamicProperty("@cdb@LoanManage@Wizard@WizardSetp3_Villige");
						lbl.setColor('red');
						lbl.setText(tip,true);
						return 'NONE';
					}
					
					lbl.setText('',true);
          this.onSaveData();
          return null; // return "NONE" to not advance panels
        }

        block.prototype.onSaveData = function() {
          var block_loan_step2_gd = this.wizard.get("block_loan_step2_gd");
          var block_loan_step3_gd = this.wizard.get("block_loan_step3_gd");
          var relatedGauranteeInfoUIO = block_loan_step2_gd.getDataAsObject();
		  /*
		  if(!relatedGauranteeInfoUIO.partyId){
			relatedGauranteeInfoUIO.partyId = this.getAncestorOfType("ux.megatron.gui.SteppedWizard").block_loan_step2_gd_partyId;
		  }
		  if(!relatedGauranteeInfoUIO.addressId1){
			relatedGauranteeInfoUIO.addressId1 = this.getAncestorOfType("ux.megatron.gui.SteppedWizard").block_loan_step2_gd_addressId1;
		  }
		  if(!relatedGauranteeInfoUIO.addressId2){
			relatedGauranteeInfoUIO.addressId2 = this.getAncestorOfType("ux.megatron.gui.SteppedWizard").block_loan_step2_gd_addressId2;
		  }*/
          
          var incoming = relatedGauranteeInfoUIO.familyIncome;         
          if(isNaN(incoming)){
          	relatedGauranteeInfoUIO.familyIncome = null;
          }
          jsx3.log("saveTwoInfo incoming: "+ relatedGauranteeInfoUIO.familyIncome);  
          
          var ps = ux.megatron.Main.getServer().getDynamicProperty("@cdb@LoanManage@MainPage@PleaseSelect");
          var healthStatusCode = relatedGauranteeInfoUIO.healthStatusCode;         
          if(healthStatusCode == ps){
          	relatedGauranteeInfoUIO.healthStatusCode = null;
          }
          jsx3.log("saveTwoInfo healthStatusCode: "+ relatedGauranteeInfoUIO.healthStatusCode);                               
                  
          //alert(relatedGauranteeInfoUIO.certTypeCode);
          var appBasicInfo = block_loan_step3_gd.getDataAsObject();
          var appAmt = appBasicInfo.appAmt;
          //var wizard = this.getAncestorOfType("ux.megatron.gui.SteppedWizard");
          jsx3.log("saveTwoInfo relatedGuaranteeType: "+ this.wizard.relatedGuaranteeType);  
          jsx3.log("saveTwoInfo appAmt:"+ appAmt); 
          var studentInfo = {studentId:this.wizard.studentId,
          	                 chnFullName:this.wizard.studentName,
          	                 certId:this.wizard.studentCertId,
          	                 schoolId:this.wizard.schoolId,
          	                 schoolName:this.wizard.schoolName};
          jsx3.log("chnFullName: "+ this.wizard.studentName);
          jsx3.log("schoolId: "+ this.wizard.schoolId);
          
		  /* cover cache data with general detail data. */
		  var params = [];
		  if(this.wizard.Operation && this.wizard.Operation == "Edit"){
	        	jsx3.log("step3: edit ***************");
				this.extend(this.wizard.loan_step2_data, relatedGauranteeInfoUIO);
				this.extend(this.wizard.loan_step3_data, appBasicInfo);
			jsx3.log('this.wizard.loan_step2_data : ' + dwr.util.toDescriptiveString(this.wizard.loan_step2_data,4));
	          params.push(this.wizard.loan_step2_data);
	          params.push(this.wizard.studentId);//studentID
	          params.push(this.wizard.loan_step2_data.relatedGuaranteeTypeCode);
	          params.push(this.wizard.loan_step3_data);
	          params.push(studentInfo);
        }else{
        	jsx3.log("step3: add***************");
			/*
        	if(!relatedGauranteeInfoUIO["addressId1"]){
        		relatedGauranteeInfoUIO["addressId1"] = null;
        	}
        	if(!relatedGauranteeInfoUIO["addressId2"]){
			relatedGauranteeInfoUIO["addressId2"] = null;
        	}
        	if(!relatedGauranteeInfoUIO["partyId"]){
        		relatedGauranteeInfoUIO["partyId"] = null;
        	}*/
		  if(this.wizard.loan_step2_data)
			this.extend(this.wizard.loan_step2_data, relatedGauranteeInfoUIO); 
		  else
			this.wizard.loan_step2_data = relatedGauranteeInfoUIO;
          params.push(this.wizard.loan_step2_data);
          params.push(this.wizard.studentId);//studentID
          params.push(this.wizard.relatedGuaranteeType);
          params.push(appBasicInfo);
          params.push(studentInfo);
        }
		  console.log('Loan#loadWizard#step3#BorrowApply onSaveData : param : \n' , params);
		  //jsx3.log('Loan#loadWizard#step3#BorrowApply onSaveData : param : \n' + dwr.util.toDescriptiveString(params,4));

          var me = this;
          ux.megatron.util.Dwr.callDwr("AcceptRetailStudentLoanAppUCC", "saveTwoInfo", 
            params, me, me.onSaveDataCallBack, "AcceptRetailStudentLoanAppUCC");
        }
        
        		
		block.prototype.extend = function(tarObj, orgObj){
			if(tarObj && orgObj)
			for(var prop in orgObj){
				tarObj[prop] = orgObj[prop];
			}
			return tarObj;
		};

        block.prototype.onSaveDataCallBack = function(reData) {
          if(!reData)
						jsx3.log("call saveTwoData failed......");
				
					var flag = reData.res.flag;

        	if(flag != 1){
        		var msg = reData.res.msg;
        		jsx3.log("call saveTwoData failed: "+msg);
        		return;
        	}
					
					var loanManage = ux.megatron.Main.getServer().getBodyBlock().getDescendantsOfType("ux.cdb.admin.loan.LoanManage")[0];
					loanManage.onRefresh();
					var cacheId = ux.cdb.admin.dataautomate.GenericDetail.Loan + ":" + this.wizard.appBasicInfoId;
					jsx3.log("onSaveDataCallBack cacheId:" + cacheId);
					ux.cdb.admin.Cache.remove(cacheId);
          this.getAncestorOfType("ux.cdb.admin.loan.loanWizard.LoanBuilder").onClose();          
        }
                
				block.prototype.onCustomNav = function(objWIZARD, objBUTTON, objEVENT, strCURRENTPANEL) {
					return null; // return "NONE" to not advance panels
				}

				block.prototype.onBeforeShow = function(objWIZARD, objBUTTON, objEVENT, strLASTPANEL) {
					jsx3.log('this.getChild(0): '+this.getChild(0)); 
					if(!this.getChild(0)) {
						var me = this;
						ux.megatron.Main.loadUIResourceAsync(me, "ux.cdb.admin","ux/cdb/admin/loan/loanWizard/step3/ui/BorrowApplyContent.xml", me, me.initialize);
					}else{
						jsx3.log('onBeforeShow else****************: '); 
						this.get('blkField_appReason').getChild(1).repaint();
      			this.get('blkField_appType').getChild(1).repaint();
					this.get("blkField_studentName").getChild(1).setText(this.wizard.studentName,true);
					this.get("blkField_studtCertId").getChild(1).setText(this.wizard.studentCertId,true);
					this.get("blkField_coDebitName").getChild(1).setText(this.wizard.coDebitName,true);
					this.get("blkField_coDebitCertType").getChild(1).setText(this.wizard.coCertType,true);
					this.get("blkField_coCertId").getChild(1).setText(this.wizard.coCertId,true);
				}
										
					return null; // return "NONE" to not advance panels
				}

				block.prototype.onAfterHide = function(objWIZARD, objBUTTON, objEVENT, strNEXTPANEL) {
					return null; // return "NONE" to not advance panels
				}
			}
	);
}
